/**
 * 首页配置管理初始化
 */
var ConfigIndex = {
    id: "ConfigIndexTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
ConfigIndex.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: 'ID', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '顶部图片', field: 'topimage', visible: true, align: 'center', valign: 'middle'},
            {title: '热销左1', field: 'rxl1', visible: true, align: 'center', valign: 'middle'},
            {title: '热销左2', field: 'rxl2', visible: true, align: 'center', valign: 'middle'},
            {title: '热销中1', field: 'rxm1', visible: true, align: 'center', valign: 'middle'},
            {title: '热销中2', field: 'rxm2', visible: true, align: 'center', valign: 'middle'},
            {title: '热销中3', field: 'rxm3', visible: true, align: 'center', valign: 'middle'},
            {title: '热销右1', field: 'rxr1', visible: true, align: 'center', valign: 'middle'},
            {title: '热销右2', field: 'rxr2', visible: true, align: 'center', valign: 'middle'},
            {title: '1楼', field: 'f1txt', visible: true, align: 'center', valign: 'middle'},
            {title: '2楼', field: 'f2txt', visible: true, align: 'center', valign: 'middle'},
            {title: '3楼', field: 'f3txt', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
ConfigIndex.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        ConfigIndex.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加首页配置
 */
ConfigIndex.openAddConfigIndex = function () {
    var index = layer.open({
        type: 2,
        title: '添加首页配置',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/configIndex/configIndex_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看首页配置详情
 */
ConfigIndex.openConfigIndexDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '首页配置详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/configIndex/configIndex_update/' + ConfigIndex.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除首页配置
 */
ConfigIndex.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/configIndex/delete", function (data) {
            Feng.success("删除成功!");
            ConfigIndex.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("configIndexId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询首页配置列表
 */
ConfigIndex.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    ConfigIndex.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = ConfigIndex.initColumn();
    var table = new BSTable(ConfigIndex.id, "/configIndex/list", defaultColunms);
    table.setPaginationType("client");
    ConfigIndex.table = table.init();
});
